package com.aliyun.messagemgt.web.controller;


import com.aliyun.messagemgt.application.service.BaseReceiveGroupService;
import com.aliyun.messagemgt.common.dto.response.ResultMap;
import com.aliyun.messagemgt.dto.base.*;
import com.aliyun.messagemgt.common.validation.ValidationGroups;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 基础表-接收组表 前端控制器
 * </p>
 *
 * @author wugongzi
 * @since 2021-09-28
 */
@RestController
@RequestMapping("/base/receive/group")
@Api(tags = "接收组")
public class BaseReceiveGroupController {

    @Autowired
    private BaseReceiveGroupService baseReceiveGroupService;

    @PostMapping
    @ApiOperation("新增接收组")
    public ResultMap<Boolean> add(@RequestBody @Validated(ValidationGroups.Insert.class) BaseReceiveGroupAddCmd cmd) {
        Boolean flag = baseReceiveGroupService.add(cmd);
        return new ResultMap<>(flag);
    }

    @PostMapping("/list")
    @ApiOperation("分页查询接收组")
    @ApiResponses({
            @ApiResponse(code = 200, message = "列表对象", response = BaseReceiveGroupDetailDTO.class)
    })
    public ResultMap<PageInfo<BaseReceiveGroupDetailDTO>> page(@RequestBody BaseReceiveGroupQry baseReceiveGroupQry) {
        PageInfo<BaseReceiveGroupDetailDTO> baseReceiveGroupDTOPageInfo = baseReceiveGroupService.page(baseReceiveGroupQry);
        return new ResultMap<>(baseReceiveGroupDTOPageInfo);
    }

    @GetMapping("/detail")
    @ApiOperation("查询接收组详情")
    @ApiResponses({
            @ApiResponse(code = 200, message = "接收组详情对象", response = BaseReceiveGroupDetailDTO.class)
    })
    public ResultMap<BaseReceiveGroupDetailDTO> detail(@ApiParam("接收组id") @RequestParam("id") Long id) {
        BaseReceiveGroupDetailDTO baseReceiveGroupDetailDTO = baseReceiveGroupService.get(id);
        return new ResultMap<>(baseReceiveGroupDetailDTO);
    }

    @DeleteMapping
    @ApiOperation("删除接收组")
    public ResultMap<Boolean> delete(@ApiParam("接收组id") @RequestParam("id") Long id) {
        Boolean flag = baseReceiveGroupService.delete(id);
        return new ResultMap<>(flag);
    }

    @PutMapping
    @ApiOperation("更新接收组")
    public ResultMap<Boolean> update(@RequestBody @Validated(ValidationGroups.Update.class) BaseReceiveGroupUpdateCmd cmd) {
        Boolean flag = baseReceiveGroupService.update(cmd);
        return new ResultMap<>(flag);
    }
}
